/**
 * @Author : wzgl5533
 * @Timestamp : 2017-07-07
 */
var do_Notification = sm("do_Notification");
var do_Page = sm("do_Page");
var do_App = sm("do_App");
var do_Global = sm("do_Global");

// 切换容器
var viewShower = ui("view_shower");
// 给viewShower绑定子页面
var viewShower_data = [{
	"id" : "chats",
	"path" : "source://view/chats/chats_index_ui.ui"
}, {
	"id" : "contacts",
	"path" : "source://view/contacts/contacts_index_ui.ui"
}, {
	"id" : "discover",
	"path" : "source://view/discover/discover_index_ui.ui"
}, {
	"id" : "me",
	"path" : "source://view/me/me_index_ui.ui"
}];

viewShower.addViews(viewShower_data);
//默认显示第一个
viewShower.showView("chats");

// 获取底部按钮
var chats_btn = ui("do_ALayout_chats");
var chats_img = ui("do_ImageView_chats");
var chats_label = ui("do_Label_chats");
chats_btn.on("touch", function() {
	showView("chats");
});

var contacts_btn = ui("do_ALayout_contacts");
var contacts_img = ui("do_ImageView_contacts");
var contacts_label = ui("do_Label_contacts");
contacts_btn.on("touch", function() {
	showView("contacts");
});

var discover_btn = ui("do_ALayout_discover");
var discover_img = ui("do_ImageView_discover");
var discover_label = ui("do_Label_discover");
discover_btn.on("touch", function() {
	showView("discover");
});

var me_btn = ui("do_ALayout_me");
var me_img = ui("do_ImageView_me");
var me_label = ui("do_Label_me");
me_btn.on("touch", function() {
	showView("me");
});

// 跳转函数
function showView(name) {

	viewShower.showView(name);

	if (name == "chats") {
		chats_img.source = "source://image/s0.png"
		chats_label.fontColor = "09BB07FF";
	} else {
		chats_img.source = "source://image/d0.png"
		chats_label.fontColor = "9F9F9FFF";
	}

	if (name == "contacts") {
		contacts_img.source = "source://image/s1.png"
		contacts_label.fontColor = "09BB07FF";
	} else {
		contacts_img.source = "source://image/d1.png"
		contacts_label.fontColor = "9F9F9FFF";
	}

	if (name == "discover") {
		discover_img.source = "source://image/s2.png"
		discover_label.fontColor = "09BB07FF";
	} else {
		discover_img.source = "source://image/d2.png"
		discover_label.fontColor = "9F9F9FFF";
	}

	if (name == "me") {
		me_img.source = "source://image/s3.png"
		me_label.fontColor = "09BB07FF";
	} else {
		me_img.source = "source://image/d3.png"
		me_label.fontColor = "9F9F9FFF";
	}
}

//当前页面下，订阅android系统返回键的事件：3秒内连续点击两次退出应用
var canBack = false;
var delay3 = mm("do_Timer");
delay3.delay = 3000;
delay3.on("tick", function() {
	delay3.stop();
	canBack = false;
});
do_Page.on("back", function() {
	if (canBack) {
//		do_Global.exit();
		do_App.closePage();
	} else {
		do_Notification.toast("再次点击退出应用");
		canBack = true;
		delay3.start();
	}
});
